'use strict'
require('./logger')
require('./requestControl')
//require('./userSerClient') //用户服务器客户端
require('./gateServer') //网关服务器
require('./rootServer') //根服务器


let sceneMgr = require('./sceneMgr')
let remoteCall = require('./remoteCall')
let playerSessionMgr = require('./playerSessionMgr')
let routes  = require('./route')
let nodeMgr = require('./nodeMgr')
//子节点注册
remoteCall.setCall('bindNodeName', function(session, msg){
    let nodeName = msg.nodeName
    nodeMgr.bind(session.id, nodeName)
})

//获取子节点的请求方法
remoteCall.setCall('getRequestRoute', function(nodeSession, msg){
    let nodeName = msg.nodeName
    let routeName = msg.routeName
    for(let i in routeName){
      routes.setNode(routeName[i], nodeName)
    }
})

//进入公共场景
remoteCall.setCall('enterScene', function(nodeSession, msg){
    let playerSession = playerSessionMgr.getByPid(msg.pId)
    sceneMgr.getSceneSerById(msg.sceneId).addClient(playerSession)
})

//推送消息到该玩家
remoteCall.setCall('pushMsgToPlayer', function(nodeSession, msg){
  playerSessionMgr.pushMsgToPlayer(msg.pId, msg.data, msg.route)
})

//推送消息到当前场景
remoteCall.setCall('pushMsgsToScene', function(nodeSession, msg){
  playerSessionMgr.pushMsgsToScene(msg.sceneId, msg.data, msg.route)
})
